package com.yf.javathread.face.test1;

/**
 * 生产者、消费者模式：synchronized、wait和notify
 *
 */
public class ProducerConsumerWithNotify {


class Resouce{
    private int num=0;
    private int size=10;

    public synchronized void add(){
        if(num<size){
            num++;
            //通知等待的消费者
            notifyAll();

        }else{

            try {
                wait();
                num++;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
}
